import { followTarget } from '@/services/consult'
import type { FollowType } from '@/types/consult'
// import type { Doctor, Knowledge } from '@/types/consult'
import { ref } from 'vue'

// hook => 钩子（勾进来数据和业务逻辑）
export const useFollow = (type: FollowType = 'doc') => {
  const loading = ref(false)
  // const follow = async (item: Doctor | Knowledge) => {
  const follow = async (item: { id: string; likeFlag: 0 | 1 }) => {
    loading.value = true
    await followTarget(item.id, type)
    item.likeFlag = item.likeFlag === 0 ? 1 : 0
    loading.value = false
  }
  return { loading, follow }
}
